package controller;

import dao.Album;
import dao.Artist;
import dao.Track;
import model.AlbumModel;
import model.ArtistModel;
import model.TrackModel;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: eee pc
 * Date: 21.02.13
 * Time: 17:51
 * To change this template use File | Settings | File Templates.
 */
public class AlbumServlet extends HttpServlet{
    private static final String ALBUM_ID = "albumId";
    private static final String ALBUM_ATTRIBUTE = "album";
    private static final String ARTIST_ATTRIBUTE = "artist";
    private static final String TRACKS_ATTRIBUTE = "tracks";
    private static final String ALBUM_VIEW = "view/album.jsp";

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String albumId = request.getParameter(ALBUM_ID);
        AlbumModel albumModel = AlbumModel.getInstance();

        Album album = albumModel.getAlbumByAlbumId(albumId);
        request.setAttribute(ALBUM_ATTRIBUTE, album);

        ArtistModel artistModel = ArtistModel.getInstance();
        Artist artist = artistModel.getArtistByAlbumId(albumId);
        request.setAttribute(ARTIST_ATTRIBUTE, artist);

        TrackModel trackModel = TrackModel.getInstance();
        List<Track> tracks = trackModel.getTracksByAlbumId(albumId);
        request.setAttribute(TRACKS_ATTRIBUTE, tracks);

        RequestDispatcher view = request.getRequestDispatcher(ALBUM_VIEW);
        view.forward(request, response);
    }
}




